import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_01: 手动点击桌面"音乐"应用, 成功进入音乐')
@allure.issue(
    'https://www.tapd.cn/56767367/sparrow/tcase/view/1156767367001043361?url_cache_key=17e362af8b12add5e45c5e468a11c15a')
class TestCaseMusic01:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()

        self.music_choice_page = CommonPage(self.driver).get_music_choice_page()
        self.music_index_page = CommonPage(self.driver).get_music_index_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('music')
        # XiaoMaUtils.clear_data('music')
        self.driver.quit()

    @allure.story("step1: 点击应用页")
    @pytest.mark.run(order=11)
    def test_music_01_1_click_app_list(self):
        try:
            self.launcher_index_page.click_app_list()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击应用中的音乐")
    @pytest.mark.run(order=12)
    def test_music_01_2_click_music(self):
        try:
            self.launcher_app_list_page.click_appname(TestCase.MUSIC)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step3: 查看音乐是否启动")
    @pytest.mark.run(order=13)
    def test_music_01_3_is_display_music(self):
        try:
            if self.music_choice_page.is_display_title():
                self.music_choice_page.click_skip()
            assert self.music_index_page.is_display_online_music()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == '__main__':
    # pass
    pytest.main("-s testcase_music_01.py")
